/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.support;

import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 
 *
 * @author haolw
 * @time 2016/09/28
 */
public abstract class PropertiesHolder {
	private static ConcurrentHashMap<String, String> cacheMap;

	static {
		cacheMap = new ConcurrentHashMap<String, String>(64);
	}

	/**
	 * 解析Properties，缓存至内存
	 * 
	 * @param props
	 */
	protected static void resolveProperties(Properties props) {
		for (Entry<Object, Object> entry : props.entrySet()) {
			String key = String.valueOf(entry.getKey());
			String value = String.valueOf(entry.getValue());
			cacheMap.put(key, value);
		}
	}

	/**
	 * 从系统缓存中得到数据，没有则得到null
	 * 
	 * @param key
	 * @return
	 */
	public static String get(String key) {
		return cacheMap.get(key);
	}

	/**
	 * 向缓存中添加数据，若原来有该数据，则被覆盖
	 * 
	 * @param key
	 * @param value
	 */
	public static void add(String key, String value) {
		cacheMap.put(key, value);
	}

	/**
	 * 想缓存中删除某数据
	 * 
	 * @param key
	 */
	public static void delete(String key) {
		cacheMap.remove(key);
	}

	/**
	 * 清空缓存
	 */
	public static void clear() {
		cacheMap.clear();
	}

}
